const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
amazonMws.setResponseFormat("text");
// const isProduction = process.env.NODE_ENV === 'production';

const d = {};

d.getMatchingProductForId = function (seller_id, mws_auth_token, marketplaceId, idList) {
    console.log('set sellerid:' + seller_id)
    let baseOption = {
        'Version': '2011-10-01',
        'Action': 'GetMatchingProductForId',
        'SellerId': seller_id,
        'MWSAuthToken': mws_auth_token,
        'MarketplaceId': marketplaceId,
        'IdType' : 'SellerSKU',
    };
    if (idList) {
        let keyPrefix = "IdList.Id";
        idList.forEach((item, index) => {
            baseOption[keyPrefix + "." + (index + 1)] = item;
        });
    }
   
    return amazonMws.products.search(baseOption);
};

module.exports = d;